const Order = require("../model/order.model")

class OrderService {
    async createOrder(order) {
        const { user_id, address_id, goods_info, total, order_number } = order
        const status = 0
        try {
            return await Order.create({ user_id, address_id, goods_info, total, order_number, status })
        } catch (error) {
            console.log(error)
        }
    }
    async findAllOrder({ pageNum, pageSize, status }) {
        const { count, rows } = await Order.findAndCountAll({
            limit: +pageSize,
            offset: (pageNum - 1) * pageSize,
            where: {
                status
            }
        })
        return {
            pageNum,
            pageSize,
            total: count,
            list: rows
        }
    }
    async updateOrder(id, status) {
        return await Order.update({ status }, {
            where: {
                id
            }
        })
    }
}

module.exports = new OrderService()